﻿/// <reference path="../IndividualCV.aspx" />
function LoadEmploymentTypeDropDown() {
    
    cacheEmpData = new Array();
    categoryCount = 1;
    var listJson;

    var ul = $('#empDropDown');    
    var select = $('<select id="ddlEmploymentType" class="selectRound" style="width:240px;" />');
    $.ajax({
        type: "POST",
        url: "HandlerSearchCV.ashx",
        data: { 'search': 'employmenttype' },
        dataType: "json",
        success: function (responseData, status, xhr) {
            listJson = responseData;
            select.append($("<option></option>").val(0).html("Any"));
            $.each(responseData, function (i, item) {
                select.append($("<option></option>").val(i+1).html(responseData[i]));

            });
            ul.html(select);
        },
        error: function (xhr, tStatus, err) {
            if (xhr.status == "401") {
                alert(xhr.status + " User Authorisation failed.Please login again.");
                location.reload();
            }
        }
    });

    //ddlDiv.appendTo(ul);
    //$('#EmploymentType').append("<br />");

    //$("button[id^='EmploymentAdd']").live("click", null, function () {
    //    categoryCount++;

    //    if (categoryCount == 3)
    //        $("button[id='EmploymentAdd']").hide();
    //    else
    //        $("button[id='EmploymentAdd']").show();

    //    var ul = $('#ulEmploymentType');
    //    var ddlDiv = $("<li class='li-style-employment'></li>");
    //    var select = $('<select id="ddlEmploymentType' + categoryCount +'" />');
    //    $.each(listJson, function (i, item) {
    //        select.append($("<option></option>").val(i).html(listJson[i]));
    //    });

    //    ddlDiv.append(select);
    //    var btnDelCat = "EmploymentDel" + categoryCount;
    //    ddlDiv.append("<button id='" + btnDelCat + "' class=\"buttonDel\" >X</button>");
    //    ul.append(ddlDiv);
    //    return false;
    //});

    //$("button[id^='EmploymentDel']").live("click", null, function () {
    //    var select = $(this).parent();
    //    select.remove();
    //    $("button[id='EmploymentAdd']").show();
    //    return false;
    //}); 

    $(document).on('change', "select[id='ddlEmploymentType']", function () {
       
        window.scrollTo(0, 0);
        $("body").ajaxLoader();
                       
        var pageSize = $('#ctl00_MainContent_ddlPageSize option:selected').val().trim();

            var jobTitleText = "";
            $("#JobTitleSearch :text").each(function () {
                jobTitleText += $(this).val() + "$";
            });

            var jobSeekerPlaceText = "";
            $("#Place :text").each(function () {
                jobSeekerPlaceText += $(this).val() + "$";
            });

            var jobCategoryText = "";
            $("#Category :text").each(function () {
                jobCategoryText += $(this).val() + "$";
            });


            var jobSeekerEmploymentType = "";
            $("#EmploymentType option:selected").each(function () {
                jobSeekerEmploymentType += $(this).text() + "$";
            });


            var jobSeekerQualification = "";
            $("#Qualification :text").each(function () {
                jobSeekerQualification += $(this).val() + "$";
            });

            var jobSeekerSkills = "";
            $("#Skills :text").each(function () {
                jobSeekerSkills += $(this).val() + "$";
            });

            var selectedUpdateTime = $('#ctl00_SearchContainer_ddlCvUpdate option:selected').text().trim();
            var selectedExperience = $('#ctl00_SearchContainer_DropDownListExperience option:selected').text().trim();

            $.ajax({
                type: "POST",
                contentType: "application/json; charset=utf-8",
                url: "SearchCV.aspx/getByEmploymentType",
                data: JSON.stringify({ 'search': $("option:selected", this).text(), 'pageSize': pageSize, 'updateTime': selectedUpdateTime, 'experience': selectedExperience, 'jobTitle': jobTitleText, 'location': jobSeekerPlaceText, 'category': jobCategoryText, 'employmentType': jobSeekerEmploymentType, 'qualification': jobSeekerQualification, 'skills': jobSeekerSkills }),
                datatype: "json",
                success: function (data) {
                    PrintGrid(data, 1);
                    $("body").ajaxLoaderRemove().delay(3000);
                },
                error: function (response, error, xhr) {
                    $("body").ajaxLoaderRemove().delay(3000);
                    if (xhr.status == "401") {
                        alert(xhr.status + " User Authorisation failed.Please login again.");
                        location.reload();
                    }
                },
                complete: function (xhr, status) {
                    var msg = xhr.responseText;
                }


            })              
    });

}